<?PHP
include "../../../mainfile.php";

//Update Mailing Address
if($_POST['action'] == 'change_address'){
	$xoopsDB->query("UPDATE " . $xoopsDB->prefix('contact_form_contact_info') . " SET mailing_addy = '".$_POST['addy']."'");
    redirect_header('index.php?op=address&currentID=0', 1, 'You have successfully updated your mailing address');
}


//Update voice Numbers
if($_POST['action'] == 'change_voice'){
	$xoopsDB->query("UPDATE " . $xoopsDB->prefix('contact_form_contact_info') . " SET voice = '".$_POST['voice']."'");
    redirect_header('index.php?op=voice&currentID=1', 1, 'Your station\'s voice phone number(s) have succesfully been updated!');

}



//Update Fax Numbers
if($_POST['action'] == 'change_fax'){
	$xoopsDB->query("UPDATE " . $xoopsDB->prefix('contact_form_contact_info') . " SET fax = '".$_POST['fax']."'");
    redirect_header('index.php?op=fax&currentID=2', 1, 'Your station\'s fax number(s) have succesfully been updated!');

}


//Update Fax Numbers
if($_POST['action'] == 'change_hours'){
	$xoopsDB->query("UPDATE " . $xoopsDB->prefix('contact_form_contact_info') . " SET hours = '".$_POST['hours']."'");
    redirect_header('index.php?op=hours&currentID=3', 1, 'Your station\'s hours of operation have succesfully been updated!');
}


//ADD NEW Subject Line / Recipient Pair
if($_POST['action'] == 'add_subject'){
	require_once('../include/Validate.php');
	$noYes = array('NO', 'YES');
	//Validate Email Addy
	if($noYes[Validate::email($_POST['recipient'], false)] == 'NO'){
	    redirect_header('index.php?op=subject&amp;currentID=4&amp;subject='.$_POST['subject'].'&amp;recipient='.$_POST['recipient'], 1, 'Please enter a valid email address before submitting!');
	}else{
		$myts =& MyTextSanitizer::getInstance();
		//$subject = ereg_replace("[^A-Za-z0-9, ' ']", "", $_POST['subject']);
		$xoopsDB->query("INSERT INTO " . $xoopsDB->prefix('contact_form_recipients') . " values ('0','".$myts->htmlSpecialChars(mysql_real_escape_string($_POST['subject']))."','".$myts->htmlSpecialChars(mysql_real_escape_string($_POST['recipient']))."','255')");
	    redirect_header('index.php?op=subject&amp;currentID=4', 1, 'You have succesfully added the following subject line and recipient: '.mysql_real_escape_string($_POST['subject']).' - '.$_POST['recipient']);
	}
}


//EDIT Subject Line / Recipient Pair
if($_POST['action'] == 'edit_subject'){ 

	require_once('../include/Validate.php');
	$noYes = array('NO', 'YES');
	//Validate Email Addy
	if($noYes[Validate::email($_POST['recipient'], false)] == 'NO'){
	    redirect_header('index.php?op=editSubject&amp;currentID=4&amp;ID='.$_POST['ID'], 1, 'Please enter a valid email address before submitting!');
		
	}else{
		//$subject = ereg_replace("[^A-Za-z0-9, ' ']", "", $_POST['subject']);
		$xoopsDB->query("UPDATE " . $xoopsDB->prefix('contact_form_recipients') . " SET subject = '".mysql_real_escape_string($_POST['subject'])."', recipient = '".$_POST['recipient']."' WHERE ID = '".$_POST['ID']."'");
	    redirect_header('index.php?op=subject&amp;currentID=4', 1, 'You have succesfully updated the selected subject line and recipient.');
	}


}


//DELETE Subject Line / Recipient Pair
if($_POST['action'] == 'delete_subject'){
	$xoopsDB->query("DELETE FROM ".$xoopsDB->prefix("contact_form_recipients")." WHERE ID=".$_POST['ID']."");
    redirect_header('index.php?op=subject&currentID=4', 1, 'You have succesfully deleted the selected Subject / Recipient!');
}



	//reorder subjects
	if($_GET['op']=='move'){
		$Rid = $_GET["Rid"];
		$weight = $_GET["weight"];
		$xoopsDB =& Database::getInstance();
		if ($_GET['direction'] == 'up'){//set weight of row that is being replaced..
			$xoopsDB->queryF("UPDATE ".$xoopsDB->prefix("contact_form_recipients")." SET weight=$weight+1 WHERE ID = ".$_GET['previous']."");
		}else{
			$xoopsDB->queryF("UPDATE ".$xoopsDB->prefix("contact_form_recipients")." SET weight=$weight-1 WHERE ID = ".$_GET['next']."");
		} 
		$xoopsDB->queryF("UPDATE ".$xoopsDB->prefix("contact_form_recipients")." SET weight=$weight WHERE ID=$Rid");
   		redirect_header('index.php?op=subject&currentID=4', 1, 'You have succesfully updated the order of subject line recipients.');
		
		}


?>